<template>
    <div>
        <Modal
                v-model="modal"
                title="添加/编辑班级类型"
                :closable="false"
                :mask-closable="false">
            <Form
                    ref="formValidate"
                    :model="formItem"
                    :rules="ruleValidate"
                    :label-width="80">
                <FormItem label="类型名称" prop="name">
                    <Input v-model="formItem.name" placeholder="班级类型"/>
                </FormItem>
            </Form>
            <div slot="footer">
                <Button type="text" size="large" @click="cancel">取消</Button>
                <Button type="primary" size="large" @click="submit('formValidate')">确定</Button>
            </div>
        </Modal>
    </div>
</template>

<script>
    export default {
        name: "TeacherForm",
        data() {
            return {
                roleList: [],
                formItem: {
                    id: '',
                    name: '',
                    parentCode: '',
                    remark: ''
                },
                ruleValidate: {
                    name: [
                        {required: true, message: '名字不能为空', trigger: 'blur'}
                    ],
                }
            }
        },
        props: ['modal', 'modify'],
        watch: {
            modify: function () {
                this.formItem = this.modify;
            }
        },
        methods: {
            submit(name) {
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        console.log(this.formItem);
                        this.formItem.parentCode = "feather";
                        this.$api.dictionarySave(this.formItem).then(() => {
                            if (this.formItem.id != '') {
                                this.$parent.cancel();
                            }
                            this.$Message.success('保存成功');
                            this.$refs[name].resetFields();
                            this.$parent.getList();
                        })
                    }
                })
            },
            cancel() {
                this.$parent.cancel()
            },
        }
    }
</script>

<style scoped>

</style>
